<?php
	/**
	 * @ignore
	 */
	if( defined("apl_".__FILE__)) return;
	define("apl_".__FILE__,"apl_".__FILE__);
	
	require_once(APL_ROOT."/db/apl_db_".APL_DB_PROVIDER.".php");
	require_once(APL_ROOT."/html/apl_html_selection.php");
	/**
	 * MYSQL-HTML Select Object
	 *
	 * Creates a combo whose values are fetched from database
	 * @package apl
	 * @subpackage html
	 */
	class AplHtmlDbSelection extends AplHtmlSelection
	{
		private $Dataset;
		private $FieldCount;
	
		public function __construct()
		{
			parent::__construct();
		}
	 	/**
	  	* Assigns An AplQuery object whose data will be dumped
	  	* @param AplQuery $qryObject
	   */
		function setDataset( $qryObject )
		{
			if( !is_a($qryObject,"AplQuery") )
			{
				throw new Exception("Wrong Parameter! Expected AplQuery Object!!",EX_PRM_NOT_VALID);
				return;
			}
			if( $qryObject->getFieldCount()>2)
			{
				throw new Exception("Query returns more than 2 columns!!",EX_DB_QUERY_ERROR);
				return;
			}
			$this->FieldCount = $qryObject->getFieldCount();
			$this->Dataset = $qryObject;
		}
	 	/**
	  	 * Dumps the contents of the Dataset
	  	 */
	 	function buildTag()
		{	
			if( !isset($this->Dataset) )
			{
				throw new Exception("No Query Object Assigned!",EX_PRM_NOT_INITIALIZED);
				return;
			}
			parent::Clear();
			$this->Dataset->firstRecord();
			do{
				$RowData = $this->Dataset->fetch();
				if( $this->FieldCount == 1)
					parent::AddPair( $RowData[0], $RowData[0]);
				else
					parent::AddPair( $RowData[0], $RowData[1]);
	
			}while( $this->Dataset->nextRecord());
			
			return parent::BuildTag();
		}
	}

?>